all: @C_EXAMPLES@ \
	testPoisson2d testPoisson3d \
	testMMdouble mtx2bin bin2mtx KernelRegression \
	@MPI_EXAMPLES@

CC=@STRUMPACK_C_COMPILER@
CXX=@STRUMPACK_CXX_COMPILER@
FC=@CMAKE_Fortran_COMPILER@
CPPFLAGS=@STRUMPACK_ALL_INCLUDE_DIRS@

CFLAGS=@STRUMPACK_ALL_C_FLAGS@
CXXFLAGS=@STRUMPACK_ALL_CXX_FLAGS@
FFLAGS=@STRUMPACK_ALL_Fortran_FLAGS@
LIBS=-L@CMAKE_INSTALL_PREFIX@/lib/ -lstrumpack @STRUMPACK_ALL_LIBS@
LDFLAGS=@OpenMP_CXX_FLAGS@ @CMAKE_EXE_LINKER_FLAGS@

sexample: sexample.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o sexample.o
	$(CXX) $(LDFLAGS) sexample.o -o $@ $(LIBS)
	$(RM) sexample.o
dexample: dexample.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o dexample.o
	$(CXX) $(LDFLAGS) dexample.o -o $@ $(LIBS)
	$(RM) dexample.o
cexample: cexample.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o cexample.o
	$(CXX) $(LDFLAGS) cexample.o -o $@ $(LIBS)
	$(RM) cexample.o
zexample: zexample.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o zexample.o
	$(CXX) $(LDFLAGS) zexample.o -o $@ $(LIBS)
	$(RM) zexample.o

testHODLR: testHODLR.cpp
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o testHODLR.o
	$(CXX) $(LDFLAGS) testHODLR.o -o $@ $(LIBS)
	$(RM) testHODLR.o

testHelmholtz: testHelmholtz.cpp genmatrix3D_core.f
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c testHelmholtz.cpp -o testHelmholtz.o
	$(FC) $(CPPFLAGS) $(FFLAGS) -c genmatrix3D_core.f -o genmatrix3D_core.o
	$(CXX) $(LDFLAGS) testHelmholtz.o genmatrix3D_core.o -o $@ $(LIBS)
	$(RM) testHelmholtz.o genmatrix3D_core.o

testPoisson2d: testPoisson2d.cpp
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o testPoisson2d.o
	$(CXX) $(LDFLAGS) testPoisson2d.o -o $@ $(LIBS)
	$(RM) testPoisson2d.o
testPoisson3d: testPoisson3d.cpp
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o testPoisson3d.o
	$(CXX) $(LDFLAGS) testPoisson3d.o -o $@ $(LIBS)
	$(RM) testPoisson3d.o
testPoisson2dMPIDist: testPoisson2dMPIDist.cpp
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o testPoisson2dMPIDist.o
	$(CXX) $(LDFLAGS) testPoisson2dMPIDist.o -o $@ $(LIBS)
	$(RM) testPoisson2dMPIDist.o
testPoisson3dMPIDist: testPoisson3dMPIDist.cpp
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o testPoisson3dMPIDist.o
	$(CXX) $(LDFLAGS) testPoisson3dMPIDist.o -o $@ $(LIBS)
	$(RM) testPoisson3dMPIDist.o

testMMdouble: testMMdouble.cpp
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o testMMdouble.o
	$(CXX) $(LDFLAGS) testMMdouble.o -o $@ $(LIBS)
	$(RM) testMMdouble.o
testMMdoubleMPIDist: testMMdoubleMPIDist.cpp
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o testMMdoubleMPIDist.o
	$(CXX) $(LDFLAGS) testMMdoubleMPIDist.o -o $@ $(LIBS)
	$(RM) testMMdoubleMPIDist.o

testMMdoubleMPIDist64: testMMdoubleMPIDist64.cpp
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o testMMdoubleMPIDist64.o
	$(CXX) $(LDFLAGS) testMMdoubleMPIDist64.o -o $@ $(LIBS)
	$(RM) testMMdoubleMPIDist64.o

mtx2bin: mtx2bin.cpp
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o mtx2bin.o
	$(CXX) $(LDFLAGS) mtx2bin.o -o $@ $(LIBS)
	$(RM) mtx2bin.o

bin2mtx: bin2mtx.cpp
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o bin2mtx.o
	$(CXX) $(LDFLAGS) bin2mtx.o -o $@ $(LIBS)
	$(RM) bin2mtx.o

KernelRegression: KernelRegression.cpp
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o KernelRegression.o
	$(CXX) $(LDFLAGS) KernelRegression.o -o $@ $(LIBS)
	$(RM) KernelRegression.o

KernelRegressionMPI: KernelRegressionMPI.cpp
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o KernelRegressionMPI.o
	$(CXX) $(LDFLAGS) KernelRegressionMPI.o -o $@ $(LIBS)
	$(RM) KernelRegressionMPI.o

clean:
	rm -f *~ *o @C_EXAMPLES@ \
		testHelmholtz testPoisson2d testPoisson3d \
		testMMdouble mtx2bin bin2mtx KernelRegression \
		@MPI_EXAMPLES@


